package fiziksobject;

import physics.Forcer;
import physics.Location;
import physics.Vector;
import physics.physicsobject;
import physics.Vector.Type;

public class Springs implements Forcer {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private double springConstant;
	private Location springLoc;
	private physicsobject massOnSpring;
	
	public void setSpringConst(double d){
		springConstant =d;
	}
	public void setSpringLoc(Location l){
		springLoc = l;
	}
	public void setMassOnSpring(physicsobject p){
		massOnSpring= p;
	}
	public Springs(double sprgCnst, Location l, physicsobject p){
		springConstant = sprgCnst;
		springLoc = l;
		massOnSpring = p;
		}

	public Vector[] getForces(physicsobject p) {
		Location massLoc = p.getLoc();
		if(massOnSpring == p){
			double x = springLoc.distanceTo(massLoc);
			double xMag = springLoc.getX() - p.getLoc().getX();
			double yMag = springLoc.getY() - p.getLoc().getY();
			Vector massDirection = new Vector(p.getLoc(), null, xMag, yMag);
			massDirection.unit();
			Vector[] vec = {massDirection.multiply(springConstant * x).toType(Vector.Type.FORCE_SPRING)};
		    return vec;
		}
		Vector[] ret = {new Vector().toType(Vector.Type.FORCE_SPRING)};
		return ret;
	}
	public double getspringConstant(){
		return springConstant;
	}
	public Location getSpringLoc(){
		return springLoc;
	}
	public physicsobject getMassOnSpring(){
		return massOnSpring;
	}

}
